<template>

  <van-form @submit="onSubmit">
  <van-field
    v-model="username"
    name="username"
    label="用户名"
    placeholder="用户名"
    :rules="[{ required: true, message: '请填写用户名' }]"
  />
  <van-field
    v-model="password"
    type="password"
    name="password"
    label="密码"
    placeholder="密码"
    :rules="[{ required: true, message: '请填写密码' }]"
  />
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit">登陆</van-button>
  </div>
</van-form>

</template>

<script>
import axios from "../utils/axios"
import Vue from 'vue';
import { Form } from 'vant';
import { Field } from 'vant';
import { Toast } from 'vant';

Vue.use(Toast);
Vue.use(Form);
Vue.use(Field);
export default {
     data() {
    return {
      username: '',
      password: '',
    };
  },
  methods: {
    onSubmit(values) {
      console.log('submit', values);
      axios.post("/userlogin",{username:values.username,password:values.password}).then(res=>{
          console.log(res.data);
          if (res.data.code == 1) {
              Toast("登陆成功")
              window.localStorage.setItem("islogin","true") // 这个值为true就代表已经等登陆了
              this.$router.push("/my")
          } else {
               window.localStorage.setItem("islogin","false") 
               Toast("登陆失败")

          }
      })
    },
  },
}
</script>

<style>

</style>